{include file="include/top"}
<style>
    td,.layui-table th{
        text-align: center;!important;
    }
</style>
<script>
    function qweqwe(id,nun){
        if($("[id = "+id+"]") && nun ==1){
            //显示内容
            $("[fid = "+id+"]").show();
            $("[id = "+id+"],[status = 'false']").hide();
            $("[id = "+id+"],[status = 'trun']").show();
        }
        if($("[id = "+id+"]") && nun ==2){
            //隐藏
            $("[fid = "+id+"]").hide();
            $("[id = "+id+"],[status = 'false']").show();
            $("[id = "+id+"],[status = 'trun']").hide();
        }
    }
    $(document).ready(function() {
        $("[cate-id='6']").hide();
        $("[status = 'trun']").hide();
    })
</script>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">权限组管理</a>
            <a>
              <cite>权限规则</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-radius layui-btn-normal" onclick="edit()"><i class="layui-icon">&#xe654;</i>添加权限</button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>权限规则</th>
                            <th>权限名称</th>
                            <th>状态</th>
                            <th>操作</th>
                        </thead>
                        <tbody class="x-cate">
                        {volist name="list" id="data"}
                        <tr cate-id='5' fid='0' >
                            <input type="hidden" id="parent" value="{$data.id}">
                            <td>{$key+1}</td>
                            <td>
                                <i class="layui-icon x-show" status='false' onclick="qweqwe('{$data.id}',1)" id="$data.id">&#xe623;</i>
                                <i class="layui-icon x-show" status='trun' onclick="qweqwe('{$data.id}',2)" id="$data.id">&#xe625;</i>
                                {$data.name}</td>
                            <td>{$data.title}</td>
                            {if $data.status == 1}
                            <td onclick="member_stop(this,'auth_rule','id','{$data.id}','status',0,'停用')"><input type="checkbox" name="switch"  lay-text="启用|停用"  checked="" lay-skin="switch"></td>
                            {else}
                            <td onclick="member_stop(this,'auth_rule','id','{$data.id}','status',1,'启用')"><input type="checkbox" name="switch"  lay-text="启用|停用" lay-skin="switch"></td>
                            {/if}
                            <td class="td-manage">
                                <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="edit('{$data.id}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del('{:url(\'Rule/delList\')}',this,'{$data.id}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                            </td>
                        </tr>
                        {volist name='data.class' id='vo'}
                        <tr cate-id='6' fid='{$vo.pid}' >
                            <input type="hidden" id="chilb" value="{$vo.pid}" />
                            <td>{$key+1}</td>
                            <td>{$vo.name}</td>
                            <td>
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                ├{$vo.title}
                            </td>
                            {if $vo.status == 1}
                            <td onclick="member_stop(this,'auth_rule','id','{$vo.id}','status',0,'停用')"><input type="checkbox" name="switch"  lay-text="启用|停用"  checked="" lay-skin="switch"></td>
                            {else}
                            <td onclick="member_stop(this,'auth_rule','id','{$vo.id}','status',1,'启用')"><input type="checkbox" name="switch"  lay-text="启用|停用" lay-skin="switch"></td>
                            {/if}
                            <td class="td-manage">
                                <button class="layui-btn layui-btn-warm layui-btn-xs"  onclick="edit('{$vo.id}')" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del('{:url(\'Rule/delList\')}',this,'{$vo.id}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                            </td>
                        </tr>
                        {/volist}
                        {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

    /*用户-停用*/
    function member_stop(obj,table,id,where,field,state,title){
        layer.confirm('确认要'+title +'吗？',function(index){
            $.ajax({
                type: 'POST',
                url: '{:url("index/updateStatus")}',
                dataType: 'json',
                data : {table:table,id:id,where:where,field:field,state:state},
                success: function(data){
                    if(data.code>0){
                        layer.msg('已'+title,{icon:1,time:1000});
                        setTimeout(function () {
                            location.reload();
                        }, 1000);
                    }else{
                        layer.msg(title+'失败',{icon:1,time:1000});
                    }

                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        });
    }

    /*用户-删除*/
    function member_del(url,obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: url,
                dataType: 'json',
                data : {id:id},
                success: function(data){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        });
    }
    function edit(id = '')
    {
        if(id==''){
            var url = '{:url("Rule/add")}';
        }else{
            var url = '{:url("Rule/edit",["id"=>"getId"])}';
            url = url.replace('getId',id);
        }
        var loading =  layer.load(0, {shade: false});
        layer.open({
            type: 2,
            title:'编辑',
            area: ['50%', '80%'],
            content: url
        });
        layer.close(loading);
    }

    function delAll (argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>
<script>var _hmt = _hmt || []; (function() {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</html>